<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>承运商列表--快递物流系统</title>
<link rel="stylesheet" href="lib/layui/css/layui.css" media="all" />
</head>
<body>
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form" lay-filter="carrierList">
			
		</form>
		<div class="layui-inline">
 			<button  class="layui-btn addcarrier_btn" lay-event="add" >添加</button>
 				</div>
			<div class="layui-inline">
				<button  class="layui-btn select_btn"  >选择</button>
			</div>
	</blockquote>
	<table id="carrierList" lay-filter="carrierList"></table>

	<!--操作-->
	<script type="text/html" id="carrierListBar">
		<a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
		<button class="layui-btn layui-btn-xs layui-btn-danger delAll_btn" lay-event="del">删除</button>
	</script>
	

	<script type="text/javascript" src="lib/layui/layui.js"></script>
	<script>
layui.use(['table','layer','jquery','form'], function(){
  table = layui.table;
  layer = parent.layer === undefined ? layui.layer : top.layer;
  $ = layui.jquery;
  form = layui.form;
  
  
  //承运商表的数据渲染
 tableIns = table.render({
    elem: '#carrierList'
    ,height: 300
    ,id:  'carrierListTable'
    ,url: 'api/carrier?op=list' //数据接口
    ,page: true //开启分页
    ,cols: [[ //表头
    	{
			title: "全选",
			width: 80,
			type: "checkbox",
			fixed: 'left'}
      ,{field: 'express_company_id', title: '序号', width:100, sort: true, fixed: 'left'}
      ,{field: 'express_company_name', title: '名称', width:100}
      ,{field: 'express_company_code', title: '快递公司编码', width:150}
      ,{field: 'phonenumber', title: '联系电话', width:140, sort: true}
      ,{field: 'remarks', title: '备注', width:120} 
      ,{field: 'create_time', title: '添加时间', width:120} 
      ,{
			title : "操作",
			fixed : 'right',
			width : 200,
			align : 'center',
			toolbar : '#carrierListBar'
		}
    ]]
  });
  

  
  
   
  
  
  function addcarrier(edit){
	  
  	var op = "";
  	if (edit == undefined || edit == null) {
  		op = "新增";
  	} else {
  		op = "编辑";
  		
  	}
      var index = layui.layer.open({
          title : op+"承运商",
          type : 2,
          area: ['650px','450px'],
          content : "page?op=addcarrier",
          success : function(layero, index){
              var body = layui.layer.getChildFrame('body', index);
              if(edit){
            	body.find("[name ='express_company_id']").prop('disabled',true)
              	body.find("#edit").prop('value',JSON.stringify(edit));
              }
              setTimeout(function(){
                  layui.layer.tips('点击此处返回承运商列表', '.layui-layer-setwin .layui-layer-close', {
                      tips: 3
                  });
              },500)
          }
      })
      //layui.layer.full(index);
      //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
     /*  $(window).on("resize",function(){
          layui.layer.full(index);
      }) */
  }
  
	//添加员工事件
	 $(".addcarrier_btn").click(function() {
		addcarrier();
	}); 
 
  
 //监听行工具栏事件
	  table.on('tool(carrierList)', function(obj){
	        var layEvent = obj.event,
	            data = obj.data;

	        if(layEvent === 'edit'){ //编辑
	        	addcarrier(data);
	            
	        } else if(layEvent === 'del'){ //删除
	            layer.confirm('确定删除该快递公司信息？',{icon:3, title:'提示信息'},function(index){
	            	
	                $.post("api/carrier?op=delete",{
	                    ids : data.express_company_id  //将需要删除的员工编号作为参数传入
	                },function(data){
	                	if (data.code == 200) {
	                		tableIns.reload(); //刷新表格数据（也即让table重新加载url）
		                    layer.close(index);//关闭弹出框
	                	} else {
	                		 layer.close(index);//关闭弹出框
	                		 layer.msg(data.msg,{icon:2});
	                	}
	                    
	                })
	            });
	        } else if(layEvent === 'look'){ //预览
	            layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问")
	        }
	    });
 
 
   //批量删除
   $(".delAll_btn").click(function(){
       var checkStatus = table.checkStatus('carrierListTable'),
           data = checkStatus.data,
           ids = [];
       if(data.length > 0) {
           for (var i in data) {
               ids.push(data[i].express_company_id);
           }
           ids = ids.join(",");
           layer.confirm('确定删除选中的承运商？', {icon: 3, title: '提示信息'}, function (index) {
                $.post("api/carrier?op=delete",{
                    ids : ids  //将需要删除的newsId作为参数传入
                },function(d){
                	if (d.code == 200) {
						layer.msg("删除成功", {
							"icon" : 1
						});
						tableIns.reload();
					} else {
						layer.msg(d.msg, {
							"icon" : 2
						});
					}
                })
           })
       }else{
           layer.msg("请选择需要删除的承运商");
       }
   })
   
  
});
</script>

</body>
</html>